import 'dart:io';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:plate_lpr/plate_lpr.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _plateLprPlugin = PlateLpr();
  String? _plate = "正在识别";

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: Column(children: [
          Text('Running: $_plate'),
          OutlinedButton(
              onPressed: () async {
                _plate = await _plateLprPlugin.recog();
                setState(() {});
              },
              child: Text('点击去识别')),
          if (_plate != null && _plate!.length > 10)
            Image.file(File(_plate!.split(";")[1]))
        ])),
      ),
    );
  }
}
